package com.tth.learn.addproperties.java;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @Author tth
 * @Date 2022/12/14 15:42
 */
public class PropertiesTest {
    public static void main(String[] args) {
        FileInputStream fis = null;
        try {
            Properties prop = new Properties();
            fis = new FileInputStream("jdbc.properties");
            // 加载流对应的文件
            prop.load(fis);

            // 获取配置文件中指定key对应的value值
            String name = prop.getProperty("name");
            String password = prop.getProperty("password");
            System.out.println("name="+name+", password="+password);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
